import service from "@/common/service";
import {getRdsUrl, rdsRequest, rdsRequestAsync} from '@/hooks/rdsServices';


/**
 * 审核盘点单
 * @param {*} objectData 审核参数
 * @param {*} cb 成功后回调方法
 */
const CountType = {
    'P': '变更盘点进度',
    'N' : '刷新新品',
    'I' : '刷新库存',
    'A' : '审核',
    'C' : '作废',
    'S' : '终止'
}
const CountProgress = (c_mode2) => {
    return {
        '1' : c_mode2 == '3' ? 'A盘' : '初盘',
        '2' : c_mode2 == '3' ?'B盘' : '复盘',
        '3' : '三盘',
        '4' : '预审',
        '5' : '确认',
        '9' : '终盘'
    }
}
const auditCount = (objectData, cb) => {
    const rdsUrl = getRdsUrl();

    const that = this;
    const { oper_type, to_progress, c_mode2 } = objectData
    const type = CountType[oper_type]
    const progress = (CountProgress(c_mode2))[to_progress]
    uni.showModal({
        title: '提示',
        content: `您确认${type}${progress ? '到' + progress :''}吗?`,
        success: async function (res) {
            if (res.confirm) {
                service.enjoyShowLoading('正在加载...');
                const result = await rdsRequest(rdsUrl.scApi, '商品盘点单', 'AuditCount', objectData);
                service.enjoyHideLoading();
                uni.showToast({
                    duration: 3500,
                    icon: 'none',
                    title: `${result.msg}`,
                    mask: true,
                });
                cb && cb();
            } else if (res.cancel) {
            }
        },
    });
}

const  auditCountInput = async (objectData, cb) => {
    const rdsUrl = getRdsUrl();

    service.enjoyShowLoading('正在加载...');
    const result = await rdsRequest(rdsUrl.scApi, '商品盘点单', 'AuditCountInput', objectData);
    service.enjoyHideLoading();
    uni.showToast({
        duration: 3500,
        icon: 'none',
        title: `${result.msg}`,
        mask: true,
    });
    cb && cb();
}

export  {
    auditCount,
    auditCountInput,
    CountType,
    CountProgress
}
